package com.zhongying.customer;

import com.zhongying.jf.service.UserQueryService;
import com.zhongying.sys.controller.AbstractController;
import com.zhongying.sys.utils.PageUtils;
import com.zhongying.sys.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/customer")
public class CustomerController extends AbstractController {

    public static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private UserQueryService userQueryService;

    @RequestMapping("/customerList.html")
    public String customerList() {
        return "customer/customerList.html";
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(String idno, String startDate, String endDate, String mobile,
                  Integer page, Integer limit, HttpServletRequest httpServletRequest){

        Map inMap = new HashMap();
        inMap.put("idno",idno == null ? null :idno.trim());
        inMap.put("startDate",startDate == null ? null :startDate.trim());
        inMap.put("endDate",endDate == null ? null :endDate.trim());
        inMap.put("mobile",mobile == null ? null :mobile.trim());

        inMap.put("offset", (page - 1) * limit);
        inMap.put("limit", limit);
        Map result = userQueryService.queryCustomerList(inMap);

        PageUtils pageUtil = new PageUtils((List<Map>) result.get("userInfoList"),(Integer) result.get("count") , limit, page);

        return R.ok().put("page", pageUtil);
    }
}
